---
# tasklist for setting up git mail hooks

- name: install needed packages
  package:
    state: present
    name:
    - git
    #- moreutils
    - python3-kitchen
    - python3-pygit2
    - fedora-messaging
  tags:
  - git
  - git/hooks
  - packages

- name: install the fedora-messaging configuration file
  template: src=git-hooks-messaging.toml dest=/etc/fedora-messaging/git-hooks-messaging.toml
  tags:
  - batcave
  - config
  - fedora-messaging
  when: inventory_hostname.startswith('batcave')

- name: create folder where we'll place the certs
  file: path=/etc/pki/rabbitmq/ owner=root group=root mode=0755 state=directory
  tags:
  - git
  - git/hooks
  - config
  - fedora-messaging
  when: inventory_hostname.startswith('batcave')

- name: install the rabbitmq certificates for batcave
  copy: src={{ item.src }}
      dest=/etc/pki/rabbitmq/{{ item.dest }}
      owner={{ item.owner }} group={{ item.group}} mode={{ item.mode }}
  with_items:
  - src: "{{private}}/files/rabbitmq/{{ env }}/pki/issued/batcave{{ env_suffix }}.crt"
    dest: git-hooks.crt
    owner: root
    group: packager
    mode: "444"
  - src: "{{private}}/files/rabbitmq/{{ env }}/pki/private/batcave{{ env_suffix }}.key"
    dest: git-hooks.key
    owner: root
    group: packager
    mode: "440"
  - src: "{{private}}/files/rabbitmq/{{ env }}/pki/ca.crt"
    dest: git-hooks.ca
    owner: root
    group: packager
    mode: "444"
  tags:
  - git
  - git/hooks
  - config
  - fedora-messaging
  when: inventory_hostname.startswith('batcave')

- name: install the git hooks
  copy: src={{item}} dest=/usr/share/git-core/ mode=0755
  with_items:
  - post-receive-fedora-messaging
  - post-receive-chained
  - post-receive-chained-forks
  - post-receive-alternativearch
  - update-block-push-origin
  tags:
  - git
  - git/hooks

- name: install the git mail hooks
  copy: src={{item}} dest=/usr/share/git-core/mail-hooks/ mode=0755
  with_items:
  - util.py
  - git.py
  - gnome-post-receive-email
  tags:
  - git
  - git/hooks
